cmake_minimum_required(VERSION 3.0.0)

project(hope-init LANGUAGES Fortran)

if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
  set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -ffree-line-length-none -ffpe-trap=invalid,zero,overflow")
  if (CMAKE_BUILD_TYPE STREQUAL "Debug")
    set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -O0 -fcheck=all -g -fbacktrace")
  else ()
    set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -Ofast")
  endif ()
  # FIXME: OpenMP causes sigmentation faults.
  # set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fopenmp")
elseif (CMAKE_Fortran_COMPILER_ID STREQUAL "Intel")
  if (CMAKE_BUILD_TYPE STREQUAL "Debug")
    set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -no-wrap-margin -O0 -check bounds -g -traceback -mkl=sequential")
  else ()
    set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -no-wrap-margin -O3 -qopenmp -align array64byte -mkl=sequential")
  endif ()
endif ()

find_package(MPI)

add_subdirectory(lib/container)
add_subdirectory(lib/string)
add_subdirectory(lib/flogger)
add_subdirectory(lib/fiona)
add_subdirectory(lib/spark)

set(sources
  src/constants_mod.F90
  src/params_mod.F90
  src/topo_mod.F90
  src/geog_data_mod.F90
  src/math_mod.F90
  src/hope_init_mod.F90
  src/hope_init.F90
  src/weno_coef_mod.F90
  src/recon_mod.F90
  src/operators_mod.F90
)

add_executable(hope_init.exe ${sources})
target_link_libraries(hope_init.exe fortran_container fortran_string flogger fiona spark)
